package jmine.tec.services.utils.replace.transformation;

import java.util.Map;

import jmine.tec.services.utils.replace.api.ServiceRow;

public abstract class AbstractMapReplaceContentTransformation extends AbstractReplaceContentTransformation {

    private final Map<String, String> replacementMap;

    /**
     * @param action
     * @param name
     * @param parameter
     */
    public AbstractMapReplaceContentTransformation(String action, String name, String parameter, Map<String, String> replacementMap) {
        super(action, name, parameter);
        this.replacementMap = replacementMap;
    }

    @Override
    protected String getNewContent(ServiceRow row) {
        String currentValue = row.getStringParameter(this.getParameter());
        if (this.replacementMap.containsKey(currentValue)) {
            return this.replacementMap.get(currentValue);
        } else {
            return currentValue;
        }
    }

    @Override
    public String toString() {
        return String.format("mapReplaceContent(%s)", this.replacementMap);
    }

}
